{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b76e5509",
   "metadata": {},
   "source": [
    "#  作业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b402fde3",
   "metadata": {},
   "source": [
    "## 随机数生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ef9a0778",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "a4a6caea",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.random.randint(60,101,size=(6,50,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31195b72",
   "metadata": {},
   "source": [
    "## 将六个班的考试成绩进行合并得到score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "dd502bd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "score = nd1.reshape(300,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02ad9a91",
   "metadata": {},
   "source": [
    "## 生成性别数组sex，水平叠加数组sex和score得到data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "380f7f66",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "sex = np.random.randint(1,3,size=(300,1))\n",
    "data = np.hstack((score,sex))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ec8df6d",
   "metadata": {},
   "source": [
    "### 分别计算男女生各科成绩统计指标：最小值、最大值、平均分、中位数、标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "9d3323f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([60, 60, 60,  1])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([100, 100, 100,   1])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([81.84246575, 81.36986301, 81.00684932,  1.        ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([82. , 82. , 81.5,  1. ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([11.4315643 , 11.37831012, 11.46316111,  0.        ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond = data[:,3] == 1#男生\n",
    "score_min = data[cond].min(axis = 0)\n",
    "score_max = data[cond].max(axis = 0)\n",
    "score_mean = data[cond].mean(axis = 0)\n",
    "score_median = np.median(data[cond],axis = 0)\n",
    "score_std = data[cond].std(axis = 0)\n",
    "display(score_min,score_max,score_mean,score_median,score_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "a1632ce6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([60, 60, 60,  2])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([100, 100, 100,   2])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([79.83766234, 80.66233766, 79.5974026 ,  2.        ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([80. , 82. , 79.5,  2. ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([11.89809042, 11.28625228, 11.52102509,  0.        ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond = data[:,3] == 2#女生\n",
    "score_min = data[cond].min(axis = 0)\n",
    "score_max = data[cond].max(axis = 0)\n",
    "score_mean = data[cond].mean(axis = 0)\n",
    "score_median = np.median(data[cond],axis = 0)\n",
    "score_std = data[cond].std(axis = 0)\n",
    "display(score_min,score_max,score_mean,score_median,score_std)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
